#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int result[13];
	memset(result, 0, 13 * sizeof(int));
	int k;
	cin>>k;
	while (k != 0)
	{
		if (result[k - 1] == 0) {
			int *circle = new int[2 * k];
			int *restore = new int[2 * k];
			//memset(circle, 1, sizeof(int) * 2 * k);
			for (int i = 0; i < k; i++)
				circle[i] = 1;
			memset(circle + k, -1, sizeof(int) * k);
			memcpy(restore, circle, sizeof(int) * 2 * k);

			int executed = 0;
			int m = k;
			int master = m + 1;
			while (true) {
				if (circle[m] == -1) {
					circle[m] = 0;
					++executed;
					if (executed == k)
					{
						result[k - 1] = master;
						cout<<master<<endl;
						break;
					}
					int incremental = master;
					while (incremental > 0) {
						++m;
						if (circle[m % (2 * k)] == 1) { 
							--m;
							int a = incremental / (2 * k - executed);
							int b = incremental % (2 * k - executed);
							
							if (b == 0 && a != 0) {
								m += ((a - 1) * 2 * k);
							} else {
								m += (a * 2 * k);
							}						
							
							if (b > k) {
								incremental = b - k;
								m += k;
							} else if (b == 0){
								m += k;
								incremental = k - executed;
							} else {
								m += b;
								incremental = 0;	
							}
						} else if (circle[m % (2 * k)] == -1) {
							--incremental;
						}
						/*if (circle[m % (2 * k)] != 0)
							--incremental;*/
					}
					m %= (2 * k);
				} else if (executed != k) {
					executed = 0;
					//m = master++;
					/*if (master % (2 * k) == 0 ) {
						master += (k + 1);
						m = master - 1;
					} else{
						m = master++;
					}*/
					if (master % (k + 1) == 0) {
						m = master++;
					} else {
						int v = master / (k + 1);
						master = (v + 1) * (k + 1);
						m = master - 1;
					}
					m %= (2 * k);
					memcpy(circle, restore, sizeof(int) * 2 * k);
				}
			}
			delete[] circle;
			delete[] restore;
		} else {
			cout<<result[k - 1]<<endl;
		}
		cin>>k;
	}
	return 0;
}